/**
 * 
 */
(function() {
	if (navigator.userAgent.match(/IEMobile\/10\.0/)) {
        var msViewportStyle = document.createElement('style');
		msViewportStyle.appendChild(document
            .createTextNode('@-ms-viewport{width:auto!important}'));
		document.querySelector('head').appendChild(msViewportStyle)
	}

	window.onload = function() {
		mainContainerModel.init();
    };
	/**
	 * 定义导航
	 */
	var navbarContainerModel = {
		curUser : ko.observable(),
		logOut : function() {
			platform.servicebreak("~/rest/shiroLogout");
		}
    };
	ko.applyBindings(navbarContainerModel, document
			.getElementById('navbar-container'));

	/**
	 * 定义主框架
	 */
	var mainContainerModel = {
		uriTitle : ko.observable(),
		currentHeight : ko.observable(),
		init : function() {
			var that = this;
			var nav = navbarContainerModel;
			platform.servicebreakAsync('~/rest/loadMenu', null, 'post').done(
					function(response) {
						if (response instanceof Object) {
							$("#menuTree").ikgMenu({
								data : response
							}).on(
									'nodeSelected',
									function(event, data) {
										mainContainerModel.frameChangeEvent(
												event, data);
									});
						}
                    });
			var userInfo = platform.getCurrentUser();
			if (userInfo instanceof Object && userInfo.nick_name != undefined) {
				nav.curUser(userInfo.nick_name);
			}
		},
		resizeEvent : function() {
			this.currentHeight($(window).height() - 80);
		},
		frameChangeEvent : function(event, data) {
			var that = this;
			if (data instanceof Object && data.url != ''
					&& data.url != undefined) {
				that.uriTitle(data.text);
				$("#mainFrame").attr("src", platform.mapUrl(data.url)).load(
					function() {
						that.currentHeight($(window).height() - 80);
				});
			}
		}
    };
	ko.applyBindings(mainContainerModel, document
			.getElementById('main-container'));
})(this);